package com.ruoyi.mp.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.mp.service.IMpAccountService;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <h3>springcloudSaas</h3>
 * <p>图文消息留言管理接口</p>
 *
 * @author : 郎兴宇
 * @date : 2024-09-29 19:24
 **/
@RestController
@RequestMapping("/comment")
public class MpCommentController {
    @Autowired
    private WxMpService wxService;
    @Autowired
    private IMpAccountService iMpAccountService;


    /**
     * 关闭已群发文章评论.
     *
     * @param id       小程序ID
     * @throws WxErrorException 若微信请求发生错误异常
     */
    @PostMapping("/close/{id}")
    @RequiresPermissions("mp:card:close")
    @Log(title = "关闭已群发文章评论.", businessType = BusinessType.INSERT)
    public AjaxResult close(@PathVariable Long id) throws WxErrorException {
        String appId = this.iMpAccountService.selectMpAccountById(id).getAppId();
        String msgDataId = "adsad";
        Integer index = 1;
        wxService.switchoverTo(appId).getCommentService().close(msgDataId,index);
        return AjaxResult.success(1);
    }

    /**
     * 2.6 删除评论..
     *
     * @param id       小程序ID
     * @throws WxErrorException 若微信请求发生错误异常
     */
    @DeleteMapping("/delete/{id}")
    @RequiresPermissions("mp:card:delete")
    @Log(title = "2.6 删除评论..", businessType = BusinessType.DELETE)
    public AjaxResult 	delete(@PathVariable Long id) throws WxErrorException {
        String appId = this.iMpAccountService.selectMpAccountById(id).getAppId();
        String msgDataId = "adsad";
        Integer index = 1;
        Long userCommentId = 1L;
        wxService.switchoverTo(appId).getCommentService().delete(msgDataId,index,userCommentId);
        return AjaxResult.success(1);
    }


    /**
     * 查看指定文章的评论数据.
     *
     * @param id       小程序ID
     * @throws WxErrorException 若微信请求发生错误异常
     */
    @GetMapping("/list/{id}")
    @RequiresPermissions("mp:card:list")
    @Log(title = "查看指定文章的评论数据.", businessType = BusinessType.DELETE)
    public AjaxResult 	list(@PathVariable Long id) throws WxErrorException {
        String appId = this.iMpAccountService.selectMpAccountById(id).getAppId();
        String msgDataId = "adsad";
        Integer index = 1;
        int begin = 1;
        int count = 10;
        int type = 1;
        return AjaxResult.success(wxService.switchoverTo(appId).getCommentService().list(msgDataId,index,begin,count,type));
    }


    /**
     * 2.4 将评论标记精选..
     *
     * @param id       小程序ID
     * @throws WxErrorException 若微信请求发生错误异常
     */
    @PutMapping("/markElect/{id}")
    @RequiresPermissions("mp:card:markElect")
    @Log(title = "2.4 将评论标记精选..", businessType = BusinessType.DELETE)
    public AjaxResult 	markElect(@PathVariable Long id) throws WxErrorException {
        String appId = this.iMpAccountService.selectMpAccountById(id).getAppId();
        String msgDataId = "adsad";
        Integer index = 1;
        Long userCommentId = 1L;
        wxService.switchoverTo(appId).getCommentService().markElect(msgDataId,index,userCommentId);
        return AjaxResult.success(1);
    }


    /**
     * 打开已群发文章评论.
     *
     * @param id       小程序ID
     * @throws WxErrorException 若微信请求发生错误异常
     */
    @GetMapping("/open/{id}")
    @RequiresPermissions("mp:card:open")
    @Log(title = "打开已群发文章评论.", businessType = BusinessType.DELETE)
    public AjaxResult 	open(@PathVariable Long id) throws WxErrorException {
        String appId = this.iMpAccountService.selectMpAccountById(id).getAppId();
        String msgDataId = "adsad";
        Integer index = 1;
        wxService.switchoverTo(appId).getCommentService().open(msgDataId,index);
        return AjaxResult.success(1);
    }



    /**
     * 2.7 回复评论.
     *
     * @param id       小程序ID
     * @throws WxErrorException 若微信请求发生错误异常
     */
    @PostMapping("/replyAdd/{id}")
    @RequiresPermissions("mp:card:replyAdd")
    @Log(title = "2.7 回复评论.", businessType = BusinessType.DELETE)
    public AjaxResult 	replyAdd(@PathVariable Long id) throws WxErrorException {
        String appId = this.iMpAccountService.selectMpAccountById(id).getAppId();
        String msgDataId = "adsad";
        Integer index = 1;
        Long userCommentId = 1L;
        String content = "回复内容";
        wxService.switchoverTo(appId).getCommentService().replyAdd(msgDataId,index,userCommentId,content);
        return AjaxResult.success(1);
    }


    /**
     *2.8 删除回复.
     *
     * @param id       小程序ID
     * @throws WxErrorException 若微信请求发生错误异常
     */
    @DeleteMapping("/replyDelete/{id}")
    @RequiresPermissions("mp:card:replyDelete")
    @Log(title = "2.8 删除回复.", businessType = BusinessType.DELETE)
    public AjaxResult replyDelete(@PathVariable Long id) throws WxErrorException {
        String appId = this.iMpAccountService.selectMpAccountById(id).getAppId();
        String msgDataId = "adsad";
        Integer index = 1;
        Long userCommentId = 1L;
        wxService.switchoverTo(appId).getCommentService().replyDelete(msgDataId,index,userCommentId);
        return AjaxResult.success(1);
    }


    /**
     * 2.5 将评论取消精选.
     *
     * @param id       小程序ID
     * @throws WxErrorException 若微信请求发生错误异常
     */
    @DeleteMapping("/unmarkElect/{id}")
    @RequiresPermissions("mp:card:unmarkElect")
    @Log(title = "2.5 将评论取消精选.", businessType = BusinessType.DELETE)
    public AjaxResult unmarkElect(@PathVariable Long id) throws WxErrorException {
        String appId = this.iMpAccountService.selectMpAccountById(id).getAppId();
        String msgDataId = "adsad";
        Integer index = 1;
        Long userCommentId = 1L;
        wxService.switchoverTo(appId).getCommentService().unmarkElect(msgDataId,index,userCommentId);
        return AjaxResult.success(1);
    }
}


